package com.example.demo.mvvm.ui.base;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by 80711 on 2018/5/16.
 */

public abstract class BaseFragment<VD extends ViewDataBinding> extends Fragment {

    protected VD databing;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        databing = DataBindingUtil.inflate(inflater ,getLayoutId() , container , false);
        init();
        databing.executePendingBindings();
        return databing.getRoot();
    }

    protected abstract void init();

    public abstract int getLayoutId();

    public <VM extends BaseViewVM> void setViewVM( int id , VM vm ){
        databing.setVariable(id , vm);
    }
}
